<%@ page language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>考勤列表</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/black/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/css/demo.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/js/validateExtends.js"></script>
</head>
<body>
<!-- 数据列表 -->
<table id="datagrid_attendance" cellspacing="0" cellpadding="0">
    <thead>
    <th data-options="field:'id', width:80">id</th>
    <th data-options="field:'courseName', width:120">课程</th>
    <th data-options="field:'studentName', width:120">学生</th>
    <th data-options="field:'type', width:80">时段</th>
    <th data-options="field:'date', width:180">日期</th>
    </thead>
</table>
<!-- 工具栏 -->
<div id="toolbar">
    <div style="float: left;"><a id="add" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">签到</a></div>
    <div style="float: left;" class="datagrid-btn-separator"></div>
    <c:if test="${usertype == '2' || usertype == '3'}">
        <div style="float: left; margin-right: 10px;"><a id="delete" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-some-delete',plain:true">删除</a></div>
    </c:if>
    <div style="float: left;" class="datagrid-btn-separator"></div>
    <div style="margin-top: 3px;">
        学生：<input id="studentList" class="easyui-textbox" name="studentList" />
        课程：<input id="courseList" class="easyui-textbox" name="courseList" />
        类型：<input id="typeList" class="easyui-textbox" name="typeList" />
        时间：<input id="date" data-options="formatter:myformatter,parser:myparser" class="easyui-datebox" name="date" />
        <a id="search-btn" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">搜索</a>
        <a id="clear-btn" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">清空搜索</a>
    </div>
</div>

<!-- 添加数据窗口 -->
<div id="addDialog" style="padding: 10px">
    <form id="addForm" method="post">
        <table cellpadding="8" >
            <tr>
                <td style="width:40px">学生:</td>
                <td colspan="3">
                    <input id="add_studentList" style="width: 200px; height: 30px;" class="easyui-textbox" name="studentId" data-options="required:true, missingMessage:'请选择学生'" />
                </td>
                <td style="width:80px"></td>
            </tr>
            <tr>
                <td style="width:40px">课程:</td>
                <td colspan="3">
                    <input id="add_courseList" style="width: 200px; height: 30px;" class="easyui-textbox" name="courseId" data-options="required:true, missingMessage:'请选择课程'" />
                </td>
                <td style="width:80px"></td>
            </tr>
            <tr>
                <td style="width:40px">类型:</td>
                <td colspan="3">
                    <input id="add_typeList" style="width: 200px; height: 30px;" class="easyui-textbox" name="type" data-options="required:true, missingMessage:'请选择类型'" />
                </td>
                <td style="width:80px"></td>
            </tr>
        </table>
    </form>
</div>

<script type="text/javascript">
    $('#datagrid_attendance').datagrid({
        title:'考勤信息列表',
        iconCls:'icon-more',//图标
        border: true,
        fit: false,
        method: "post",
        url: "/attendance/list", //[[@{/attendance/getAttendanceList}]]
        pagination: true,//分页控件
        rownumbers: true,//行号
        toolbar: "#toolbar",
    });
    $("#add").click(function (){
        $("#addDialog").dialog('open');
    });
    $("#edit").click(function(){
        var selectRows = $("#datagrid_attendance").datagrid("getSelections");
        if(selectRows.length != 1){
            $.messager.alert("消息提醒", "请选择一条数据进行操作!", "warning");
        } else{
            $("#editDialog").dialog("open");
        }
    });
    $("#studentList").combobox({
        width: "80",
        height: "25",
        valueField: "id",
        textField: "username",
        multiple: false, //可多选
        editable: false, //不可编辑
        method: "post",
        url: "/student/comboboxList",

    });
    $("#courseList").combobox({
        width: "80",
        height: "25",
        valueField: "id",
        textField: "name",
        multiple: false, //可多选
        editable: false, //不可编辑
        method: "post",
        url: "/course/comboboxList",
    });
    //设置添加窗口
    $("#addDialog").dialog({
        title: "添加考勤信息",
        width: 450,
        height: 300,
        iconCls: "icon-add",
        modal: true,
        collapsible: false,
        minimizable: false,
        maximizable: false,
        draggable: true,
        closed: true,
        buttons: [
            {
                text:'添加',
                plain: true,
                iconCls:'icon-book-add',
                handler:function(){
                    var validate = $("#addForm").form("validate");
                    if(!validate){
                        $.messager.alert("消息提醒","请检查你输入的数据!","warning");
                        return;
                    } else{
                        $.ajax({
                            type: "post",
                            url: "/attendance/add",  //[[@{/attendance/addAttendance}]]
                            data: $("#addForm").serialize(),
                            success: function(data){
                                if(data.success){
                                    $.messager.alert("消息提醒",data.message,"info");
                                    //关闭窗口
                                    $("#addDialog").dialog("close");
                                    //清空原表格数据
                                    $("#add_name").textbox('setValue', "");
                                    //刷新
                                    $('#datagrid_attendance').datagrid("reload");
                                }else{
                                    $.messager.alert("消息提醒",data.message,"warning");
                                    return;

                                }
                            }
                        });
                    }
                }
            },
            {
                text:'重置',
                plain: true,
                iconCls:'icon-book-reset',
                handler:function(){
                    $("#add_name").textbox('setValue', "");
                }
            },
        ]
    });
    //下拉框通用属性
    $("#add_courseList,#courseList,#add_typeList").combobox({
        width: "200",
        height: "30",
        valueField: "id",
        textField: "name",
        multiple: false, //不可多选
        editable: false, //不可编辑
        method: "post",
    });
    $("#add_studentList,#studentList").combobox({
        width: "200",
        height: "30",
        valueField: "id",
        textField: "username",
        multiple: false, //不可多选
        editable: false, //不可编辑
        method: "post",
    });


    //添加信息学生选择框
    $("#add_studentList").combobox({
        url: "/student/comboboxList",  //[[@{/student/getStudentList(from=combox)}]]
        onLoadSuccess: function(){
            //默认选择第一条数据
            var data = $(this).combobox("getData");
            $(this).combobox("setValue", data[0].id);
            $(this).combobox("setText", data[0].username)
        }
    });

    //添加信息课程选择框
    $("#add_courseList").combobox({
        url: "/course/comboboxList",   //[[@{/course/getCourseList(from=combox)}]]
        onLoadSuccess: function(){
            //默认选择第一条数据
            var data = $(this).combobox("getData");
            $(this).combobox("setValue", data[0].id);
            $(this).combobox("setText", data[0].name)
        }

    });

    var typeData = [{id:"上午",text:"上午"},{id:"下午",text:"下午"}];
    $("#add_typeList").combobox({
        data:typeData,
        valueField: 'id',
        textField: 'text',
        onLoadSuccess: function(){
            //默认选择第一条数据
            var data = $(this).combobox("getData");
            $(this).combobox("setValue", data[0].id);
            $(this).combobox("setText", data[0].text);
        }
    });

    $("#typeList").combobox({
        data:typeData,
        valueField: 'id',
        textField: 'text',
        width: "80",
        height: "25",
    });
    //搜索按钮监听事件
    $("#search-btn").click(function(){
        $('#datagrid_attendance').datagrid('load',{
            studentId: $("#studentList").combobox('getValue') == '' ? 0 : $("#studentList").combobox('getValue'),
            courseId: $("#courseList").combobox('getValue') == '' ? 0 : $("#courseList").combobox('getValue'),
            type: $("#typeList").combobox('getValue') == '' ? '' : $("#typeList").combobox('getValue'),
            date:$("#date").datebox('getValue') == '' ? '' : $("#date").datebox('getValue'),
        });
    });
</script>
</body>
</html>